package com.guigu.controller.stock;


import com.guigu.pojo.stock.SysMenus;
import com.guigu.service.stock.SysMenusService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Mr.Zhang
 * @since 2024-12-06
 */
@Controller
@RequestMapping("/sys-menus")
public class SysMenusController {

    @Autowired
    private SysMenusService sysMenusService;

    // 初始化导航栏
    @GetMapping("/initialNav")
    @ResponseBody
    public ArrayList<SysMenus> initialNav(HttpServletRequest req) {
        // 通过GET获取用户的角色编号
        Integer roleId = StringUtils.isNotBlank(req.getParameter("roleId")) ? Integer.parseInt(req.getParameter("roleId")) : null;
        // 调用业务逻辑层的方法，根据角色编号查询对应的菜单信息
        ArrayList<SysMenus> sysMenus = sysMenusService.selectNavMenusByRoleId(roleId);

        return sysMenus;
    }
    // 初始化左侧导航栏
    @GetMapping("/initialList")
    @ResponseBody
    public ArrayList<SysMenus> initialLeftNav(HttpServletRequest req) {
        // 通过GET获取用户的角色编号
        Integer roleId = StringUtils.isNotBlank(req.getParameter("roleId"))? Integer.parseInt(req.getParameter("roleId")) : null;
        // 调用业务逻辑层的方法，根据角色编号查询对应的菜单信息
        ArrayList<SysMenus> sysMenus = sysMenusService.selectSysMenusByRoleId(roleId);
        return sysMenus;
    }



}

